from tools.log import GetLogging

logger = GetLogging().get_logging()


class ApiLogin:
    @staticmethod
    def api_post_login(session, url, accounts, pwd, verify, login_type):
        try:
            logger.info(f"准备发送登录请求 - 账号: {accounts}, 登录类型: {login_type}")

            # 定义请求头
            headers = {"Content-Type": "application/json"}
            logger.info("初始化请求头完成")

            # 定义请求数据
            data = {"accounts": accounts, "pwd": pwd, "verify": verify, "type": login_type}

            # 日志中密码脱敏处理
            log_data = data.copy()
            log_data["pwd"] = "******"
            logger.info("登录请求数据准备完成")

            # 发送POST请求
            logger.info("开始发送登录POST请求")
            response = session.post(url, headers=headers, json=data)

            # 记录响应状态
            logger.info(f"登录请求完成，响应状态码: {response.status_code}")

            return response

        except Exception as e:
            logger.error(f"登录请求过程发生错误: {str(e)}", exc_info=True)
            raise
